package com.yunwaikeji.gy_tool_library.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.yunwaikeji.gy_tool_library.R;
import com.yunwaikeji.gy_tool_library.utils.display.GYDisplayUtils;
import com.yunwaikeji.gy_tool_library.info.GYMenuViewInfo;
import com.yunwaikeji.gy_tool_library.utils.GYUtils;
import com.yunwaikeji.gy_tool_library.view.GYImageView;
import com.yunwaikeji.gy_tool_library.view.GYLinearLayout;
import com.yunwaikeji.gy_tool_library.view.GYTextView;
import com.yunwaikeji.gy_tool_library.view.GYView;

import java.util.Arrays;
import java.util.List;

public class GYMenuView extends GYLinearLayout implements GYMenuViewInfo {
    public GYMenuView(Context context) {
        super(context);
        init(null);
    }

    public GYMenuView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(attrs);
    }

    public GYMenuView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(attrs);
    }

    public GYMenuView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(attrs);
    }

    public GYMenuView setPaddingDp(int leftDp, int topDp, int rightDp, int bottomDp) {
        return setPaddingPx(GYDisplayUtils.dp2px(getContext(), leftDp), GYDisplayUtils.dp2px(getContext(), topDp), GYDisplayUtils.dp2px(getContext(), rightDp), GYDisplayUtils.dp2px(getContext(), bottomDp));
    }

    public GYMenuView setPaddingPx(int leftPx, int topPx, int rightPx, int bottomPx) {
        super.setPadding(leftPx, topPx, rightPx, bottomPx);
        return this;
    }

    public GYMenuView setLeftTextBold(boolean leftTextBold) {
        leftTV.getViewSet().setBold(leftTextBold);
        return this;
    }

    public boolean isLeftTextBold() {
        return leftTV.getViewSet().isBold();
    }

    public GYMenuView setLeftSingleLine(boolean leftSingleLine) {
        this.leftSingleLine = leftSingleLine;
        leftTV.setSingleLine(leftSingleLine);
        return this;
    }

    public GYMenuView setLeftMaxLength(int leftMaxLength) {
        this.leftMaxLength = leftMaxLength;
        leftTV.getViewSet().setMaxLength(leftMaxLength);
        return this;
    }

    public GYMenuView setRightTextBold(boolean rightTextBold) {
        rightContentET.getViewSet().setBold(rightTextBold);
        return this;
    }

    public boolean isRightTextBold() {
        return rightContentET.getViewSet().isBold();
    }

    public GYMenuView setTextSizePx(int textSizePx) {
        this.textSizePx = textSizePx;
        return setTextSizeSp(GYDisplayUtils.px2sp(getContext(), textSizePx));
    }

    public GYMenuView setTextSizeSp(int textSizeSp) {
        setLeftTextSizeSp(textSizeSp);
        setRightTextSizeSp(textSizeSp);
        return this;
    }

    public GYMenuView setTextColor(int textColor) {
        this.textSizePx = textColor;
        leftTV.setTextColor(textColor);
        rightContentET.setTextColor(textColor);
        return this;
    }

    public GYMenuView setLeftSrcVisibility(int visibility) {
        leftImageView.setVisibility(visibility);
        return this;
    }

    public GYMenuView setLeftHint(String text) {
        leftHint = text;
        leftTV.setHint(leftHint);
        return this;
    }

    public GYMenuView setLeftTextSizePx(int leftTextSizePx) {
        this.leftTextSizePx = leftTextSizePx;
        leftTV.setTextSize(GYDisplayUtils.px2sp(getContext(), leftTextSizePx));
        return this;
    }

    public int getLeftTextSizePx() {
        return leftTextSizePx;
    }

    public int getRightTextSizePx() {
        return rightTextSizePx;
    }

    public GYMenuView setLeftTextSizeSp(int leftTextSizeSp) {
        return setLeftTextSizePx(GYDisplayUtils.sp2px(getContext(), leftTextSizeSp));
    }

    public GYMenuView setRightHint(String rightHint) {
        this.rightHint = rightHint;
        rightContentET.setHint(rightHint);
        return this;
    }

    public GYMenuView setRightMaxLength(int rightMaxLength) {
        this.rightMaxLength = rightMaxLength;
        rightContentET.getViewSet().setMaxLength(rightMaxLength);
        return this;
    }

    public GYMenuView setRightSingleLine(boolean rightSingleLine) {
        this.rightSingleLine = rightSingleLine;
        rightContentET.setSingleLine(rightSingleLine);
        return this;
    }

    public GYMenuView setRightTextSizePx(int rightTextSizePx) {
        this.rightTextSizePx = rightTextSizePx;
        rightContentET.setTextSize(GYDisplayUtils.px2sp(getContext(), rightTextSizePx));
        return this;
    }

    public GYMenuView setRightTextSizeSp(int rightTextSizeSp) {
        return setRightTextSizePx(GYDisplayUtils.sp2px(getContext(), rightTextSizeSp));
    }

    public GYMenuView setLeftHintColor(int color) {
        leftHintColor = color;
        leftTV.setHintTextColor(leftHintColor);
        return this;
    }

    public GYMenuView setLeftTextViewVisibility(int visibility) {
        leftTV.setVisibility(visibility);
        return this;
    }

    public GYMenuView setLeftSpacingDp(int leftSpacingDp) {
        return setLeftSpacingPx(GYDisplayUtils.dp2px(getContext(), leftSpacingDp));
    }

    public GYMenuView setLeftSpacingPx(int leftSpacingPx) {
        this.leftSpacingPx = leftSpacingPx;
        initLeftSpacing();
        return this;
    }

    public GYMenuView setLeftDrawable(Drawable leftDrawable) {
        if (leftDrawable == null) {
            leftImageView.getViewSet().setVisibility(View.GONE);
        } else {
            leftImageView.getViewSet().setVisibility(View.VISIBLE);
            leftImageView.getImageBuilder().setImageDrawable(leftDrawable).build();
        }
        return this;
    }

    public GYMenuView setLeftDrawableSizePx(int leftDrawableWidthPx, int leftDrawableHeightPx) {
        leftImageView.getViewSet().setSizePx(leftDrawableWidthPx, leftDrawableHeightPx);
        return this;
    }

    public GYMenuView setLeftDrawableSizeDp(int leftDrawableWidthDp, int leftDrawableHeightDp) {
        leftImageView.getViewSet().setSizeDp(leftDrawableWidthDp, leftDrawableHeightDp);
        return this;
    }

    public GYMenuView setLeftDrawableWidthPx(int leftDrawableWidthPx) {
        leftImageView.getViewSet().setWidthPx(leftDrawableWidthPx);
        return this;
    }

    public GYMenuView setLeftDrawableWidthDp(int leftDrawableWidthDp) {
        leftImageView.getViewSet().setWidthDp(leftDrawableWidthDp);
        return this;
    }

    public GYMenuView setLeftDrawableHeightPx(int leftDrawableHeightPx) {
        leftImageView.getViewSet().setHeightPx(leftDrawableHeightPx);
        return this;
    }

    public GYMenuView setLeftDrawableHeightDp(int leftDrawableHeightDp) {
        leftImageView.getViewSet().setHeightDp(leftDrawableHeightDp);
        return this;
    }

    public GYMenuView setRightDrawable(Drawable rightDrawable) {
        if (rightDrawable == null) {
            rightImageView.getViewSet().setVisibility(View.GONE);
        } else {
            rightImageView.getViewSet().setVisibility(View.VISIBLE);
            rightImageView.getImageBuilder().setImageDrawable(rightDrawable).build();
        }
        return this;
    }

    public GYMenuView setRightDrawableSizePx(int rightDrawableWidthPx, int rightDrawableHeightPx) {
        rightImageView.getViewSet().setSizePx(rightDrawableWidthPx, rightDrawableHeightPx);
        return this;
    }

    public GYMenuView setRightDrawableSizeDp(int rightDrawableWidthDp, int rightDrawableHeightDp) {
        rightImageView.getViewSet().setSizeDp(rightDrawableWidthDp, rightDrawableHeightDp);
        return this;
    }

    public GYMenuView setRightDrawableWidthPx(int rightDrawableWidthPx) {
        rightImageView.getViewSet().setWidthPx(rightDrawableWidthPx);
        return this;
    }

    public GYMenuView setRightDrawableWidthDp(int rightDrawableWidthDp) {
        rightImageView.getViewSet().setWidthDp(rightDrawableWidthDp);
        return this;
    }

    public GYMenuView setRightDrawableHeightPx(int rightDrawableHeightPx) {
        rightImageView.getViewSet().setHeightPx(rightDrawableHeightPx);
        return this;
    }

    public GYMenuView setRightDrawableHeightDp(int rightDrawableHeightDp) {
        rightImageView.getViewSet().setHeightDp(rightDrawableHeightDp);
        return this;
    }

    public GYMenuView setDrawableSizePx(int drawableWidthPx, int drawableHeightPx) {
        setLeftDrawableSizePx(drawableWidthPx, drawableHeightPx);
        setRightDrawableSizePx(drawableWidthPx, drawableHeightPx);
        return this;
    }

    public GYMenuView setDrawableSizeDp(int drawableWidthDp, int drawableHeightDp) {
        setLeftDrawableSizeDp(drawableWidthDp, drawableHeightDp);
        setRightDrawableSizeDp(drawableWidthDp, drawableHeightDp);
        return this;
    }

    public GYImageView getLeftImageView() {
        return leftImageView;
    }

    public TextView getLeftTextView() {
        return leftTV;
    }

    public GYEditText getRightEditView() {
        return rightContentET;
    }

    public CharSequence getRightText() {
        return rightContentET.getText();
    }

    public CharSequence getRightHint() {
        return rightContentET.getHint();
    }

    public String getRightHintString() {
        if (TextUtils.isEmpty(getRightHint())) {
            return "";
        }
        return getRightHint().toString();
    }

    public GYMenuView setStyle(@Style int style) {
        if (onStyleChangeListener != null) {
            onStyleChangeListener.onStateChange(this, this.style, style);
        }
        this.style = style;
        initState();
        return this;
    }

    public GYTextView getLeftTV() {
        return leftTV;
    }

    public CharSequence getLeftHint() {
        return leftTV.getHint();
    }

    public String getLeftHintString() {
        if (TextUtils.isEmpty(getLeftHint())) {
            return "";
        }
        return getLeftHint().toString();
    }

    public CharSequence getLeftText() {
        return leftTV.getText();
    }

    public String getLeftTextString() {
        if (TextUtils.isEmpty(getLeftText())) {
            return "";
        }
        return getLeftText().toString();
    }

    public int getRightMaxLength() {
        return rightMaxLength;
    }

    public GYImageView getRightImageView() {
        return rightImageView;
    }

    public GYEditText getRightET() {
        return rightContentET;
    }

    public @Style
    int getStyle() {
        return style;
    }

    public GYMenuView setRightText(String rightText) {
        rightContentET.setText(rightText);
        return this;
    }

    public GYMenuView setRightText(Integer integer) {
        return setRightText(String.valueOf(integer));
    }

    public GYMenuView setRightTextColor(int color) {
        rightContentET.setTextColor(color);
        return this;
    }

    public GYMenuView setRightHintColor(int color) {
        rightContentET.setHintTextColor(color);
        return this;
    }

    public String getRightTextString() {
        if (TextUtils.isEmpty(rightContentET.getText())) {
            return "";
        }
        return rightContentET.getText().toString();
    }

    public GYMenuView setTextHintColor(int color) {
        setLeftHintColor(color);
        setRightHintColor(color);
        return this;
    }

    public GYMenuView setLeftText(String text) {
        leftText = text;
        leftTV.setText(leftText);
        return this;
    }

    public GYMenuView setLeftText(Object object) {
        return setLeftText(String.valueOf(object));
    }

    public GYMenuView setLeftTextColor(int color) {
        leftTextColor = color;
        leftTV.setTextColor(leftTextColor);
        return this;
    }

    public GYMenuView setLineShow(int lineShow) {
        this.lineShow = lineShow;
        switch (lineShow) {
            case Line.HIDE:
                topLineView.setVisibility(GONE);
                bottomLineView.setVisibility(GONE);
                break;
            case Line.TOP:
                topLineView.setVisibility(VISIBLE);
                bottomLineView.setVisibility(GONE);
                break;
            case Line.BOTTOM:
                topLineView.setVisibility(GONE);
                bottomLineView.setVisibility(VISIBLE);
                break;
            case Line.ALL:
                topLineView.setVisibility(VISIBLE);
                bottomLineView.setVisibility(VISIBLE);
                break;
        }
        return this;
    }

    public int getLineShow() {
        return lineShow;
    }

    public GYMenuView setLineColor(int color) {
        lineColor = color;
        topLineView.setBackgroundColor(lineColor);
        bottomLineView.setBackgroundColor(lineColor);
        return this;
    }

    public GYMenuView setLineHeightPx(int heightPx) {
        lineHeight = heightPx;
        LayoutParams layoutParams = new LayoutParams(MATCH_PARENT, lineHeight);
        topLineView.setLayoutParams(layoutParams);
        bottomLineView.setLayoutParams(layoutParams);
        return this;
    }

    public GYMenuView setLineHeightDp(int heightDp) {
        return setLineHeightPx(GYDisplayUtils.dp2px(getContext(), heightDp));
    }

    public GYMenuView setMarginLeftDp(int marginLeftDp) {
        return setMarginLeftPx(GYDisplayUtils.dp2px(getContext(), marginLeftDp));
    }

    public GYMenuView setMarginLeftPx(int marginLeftPx) {
        this.marginLeftPx = marginLeftPx;
        initContentLL();
        return this;
    }

    public GYMenuView setMarginRightDp(int marginRightDp) {
        return setMarginRightPx(GYDisplayUtils.dp2px(getContext(), marginRightDp));
    }

    public GYMenuView setMarginRightPx(int marginRightPx) {
        this.marginRightPx = marginRightPx;
        initContentLL();
        return this;
    }

    public GYMenuView setRightSpacingDp(int rightSpacingDp) {
        return setRightSpacingPx(GYDisplayUtils.dp2px(getContext(), rightSpacingDp));
    }

    public GYMenuView setRightSpacingPx(int rightSpacingPx) {
        this.rightSpacingPx = rightSpacingPx;
        initRightSpacing();
        return this;
    }

    public GYMenuView setSpacingDp(int spacingDp) {
        return setSpacingPx(GYDisplayUtils.dp2px(getContext(), spacingDp));
    }

    public GYMenuView setSpacingPx(int spacingPx) {
        this.spacingPx = spacingPx;
        initSpacing();
        return this;
    }

    public int getSpacingPx() {
        return spacingPx;
    }

    private GYImageView leftImageView;
    private GYImageView rightImageView;
    private GYTextView leftTV;
    //右边↓↓
//    private GYTextView rightContentTv;
    private GYEditText rightContentET;
    private GYImageView contentIv;
    private GYSwitch contentSwitch;
    //右边↑上
    private GYView topLineView;
    private GYView bottomLineView;
    private GYLinearLayout contentLL;
    private GYLinearLayout rightLL;

    private int textSizePx = WRAP_CONTENT;
    private int textColor = WRAP_CONTENT;
    private int textHintColor = WRAP_CONTENT;
    private int leftSpacingPx = 0;
    private int rightSpacingPx = 0;
    private int style = Style.NORMAL;
    private String leftText;
    private String leftHint;
    private String rightText;
    private String rightHint;
    private int leftHintColor = Color.GRAY;
    private int leftTextColor = Color.BLACK;
    private int leftTextSizePx = WRAP_CONTENT;
    private int rightHintColor = Color.GRAY;
    private int rightTextColor = Color.BLACK;
    private int rightTextSizePx = WRAP_CONTENT;
    private int lineShow = Line.HIDE;

    private int normalTextSize = GYDisplayUtils.sp2px(getContext(), 14);

    private int marginLeftPx = 0;
    private int marginRightPx = 0;

    private int lineColor = Color.LTGRAY;
    private int lineHeight = 1;
    private int lineMarginLeftPx = 0;
    private int lineMarginRightPx = 0;

    private int textCursorDrawable = 0;
    private int textCursorColor = Color.BLACK;
//    private int textCursorWidth = GYDisplayUtils.dp2px(getContext(), 1);

    private boolean leftSingleLine = false;
    private boolean rightSingleLine = false;
    private int leftMaxLength = 999999999;
    private int rightMaxLength = 999999999;
    private int spacingPx = 0;

    private boolean leftTextBold = false;
    private boolean rightTextBold = false;

    private int inputType;
    private String textWidthProportion;

    private float paddingLeft = 0;
    private float paddingTop = 0;
    private float paddingRight = 0;
    private float paddingBottom = 0;
    private int gravity = Gravity.CENTER_VERTICAL;

    private void init(AttributeSet attributeSet) {
        LayoutInflater.from(getContext()).inflate(R.layout.view_gy_menu, this);
        contentLL = findViewById(R.id.contentLL);
        rightLL = findViewById(R.id.rightLL);
        leftImageView = findViewById(R.id.gyMenuTitleImg);
        rightImageView = findViewById(R.id.rightImg);
        leftTV = findViewById(R.id.gyMenuLeftTV);
        rightContentET = findViewById(R.id.gyMenuRightET);
        contentIv = findViewById(R.id.contentIV);
        contentSwitch = findViewById(R.id.contentSwitch);
        topLineView = findViewById(R.id.topLineView);
        bottomLineView = findViewById(R.id.bottomLineView);
        Drawable leftDrawable = null;
        int leftDrawableWidthPx = WRAP_CONTENT;
        int leftDrawableHeightPx = WRAP_CONTENT;
        Drawable rightDrawable = null;
        int rightDrawableWidthPx = WRAP_CONTENT;
        int rightDrawableHeightPx = WRAP_CONTENT;
        float padding = WRAP_CONTENT;
        if (attributeSet != null) {
            TypedArray typedArray = getContext().obtainStyledAttributes(attributeSet, R.styleable.GYMenuView);
            textSizePx = typedArray.getDimensionPixelSize(R.styleable.GYMenuView_textSize, textSizePx);
            textColor = typedArray.getColor(R.styleable.GYMenuView_textColor, textColor);
            textHintColor = typedArray.getColor(R.styleable.GYMenuView_textHintColor, textHintColor);
            leftDrawable = typedArray.getDrawable(R.styleable.GYMenuView_leftDrawable);
            rightDrawable = typedArray.getDrawable(R.styleable.GYMenuView_rightDrawable);
            leftSpacingPx = typedArray.getDimensionPixelSize(R.styleable.GYMenuView_leftPadding, leftSpacingPx);
            rightSpacingPx = typedArray.getDimensionPixelSize(R.styleable.GYMenuView_rightPadding, rightSpacingPx);
            leftDrawableWidthPx = typedArray.getDimensionPixelSize(R.styleable.GYMenuView_leftDrawableWidth, leftDrawableWidthPx);
            leftDrawableHeightPx = typedArray.getDimensionPixelSize(R.styleable.GYMenuView_leftDrawableHeight, leftDrawableHeightPx);
            rightDrawableWidthPx = typedArray.getDimensionPixelSize(R.styleable.GYMenuView_rightDrawableWidth, rightDrawableWidthPx);
            rightDrawableHeightPx = typedArray.getDimensionPixelSize(R.styleable.GYMenuView_rightDrawableHeight, rightDrawableHeightPx);
            style = typedArray.getInteger(R.styleable.GYMenuView_style, style);
            leftText = typedArray.getString(R.styleable.GYMenuView_leftText);
            leftHint = typedArray.getString(R.styleable.GYMenuView_leftHint);
            leftHintColor = typedArray.getColor(R.styleable.GYMenuView_leftHintColor, leftHintColor);
            rightText = typedArray.getString(R.styleable.GYMenuView_rightText);
            rightHint = typedArray.getString(R.styleable.GYMenuView_rightHint);
            leftTextColor = typedArray.getColor(R.styleable.GYMenuView_leftTextColor, leftTextColor);
            leftTextSizePx = typedArray.getDimensionPixelSize(R.styleable.GYMenuView_leftTextSize, leftTextSizePx);
            rightTextColor = typedArray.getColor(R.styleable.GYMenuView_rightTextColor, rightTextColor);
            rightHintColor = typedArray.getColor(R.styleable.GYMenuView_rightHintColor, rightHintColor);
            lineColor = typedArray.getColor(R.styleable.GYMenuView_lineColor, lineColor);
            rightTextSizePx = typedArray.getDimensionPixelSize(R.styleable.GYMenuView_rightTextSize, rightTextSizePx);
            lineShow = typedArray.getInteger(R.styleable.GYMenuView_lineShow, lineShow);
            lineMarginLeftPx = typedArray.getDimensionPixelSize(R.styleable.GYMenuView_lineMarginLeft, lineMarginLeftPx);
            lineMarginRightPx = typedArray.getDimensionPixelSize(R.styleable.GYMenuView_lineMarginRight, lineMarginRightPx);
            marginLeftPx = typedArray.getDimensionPixelSize(R.styleable.GYMenuView_marginLeft, marginLeftPx);
            marginRightPx = typedArray.getDimensionPixelSize(R.styleable.GYMenuView_marginRight, marginRightPx);
            lineHeight = typedArray.getDimensionPixelSize(R.styleable.GYMenuView_lineHeight, lineHeight);
            textCursorDrawable = typedArray.getResourceId(R.styleable.GYMenuView_textCursorDrawable, textCursorDrawable);
            textCursorColor = typedArray.getColor(R.styleable.GYMenuView_textCursorColor, textCursorColor);
            leftSingleLine = typedArray.getBoolean(R.styleable.GYMenuView_leftSingleLine, leftSingleLine);
            rightSingleLine = typedArray.getBoolean(R.styleable.GYMenuView_rightSingleLine, rightSingleLine);
            leftMaxLength = typedArray.getInteger(R.styleable.GYMenuView_leftMaxLength, leftMaxLength);
            rightMaxLength = typedArray.getInteger(R.styleable.GYMenuView_rightMaxLength, rightMaxLength);
            spacingPx = typedArray.getDimensionPixelSize(R.styleable.GYMenuView_spacing, spacingPx);
            leftTextBold = typedArray.getBoolean(R.styleable.GYMenuView_leftTextBold, leftTextBold);
            rightTextBold = typedArray.getBoolean(R.styleable.GYMenuView_rightTextBold, rightTextBold);
            inputType = typedArray.getInt(R.styleable.GYMenuView_android_inputType, WRAP_CONTENT);
            textWidthProportion = typedArray.getString(R.styleable.GYMenuView_textWidthProportion);

            padding = typedArray.getDimension(R.styleable.GYMenuView_android_padding, padding);
            paddingLeft = typedArray.getDimension(R.styleable.GYMenuView_android_paddingLeft, paddingLeft);
            paddingTop = typedArray.getDimension(R.styleable.GYMenuView_android_paddingTop, paddingTop);
            paddingRight = typedArray.getDimension(R.styleable.GYMenuView_android_paddingRight, paddingRight);
            paddingBottom = typedArray.getDimension(R.styleable.GYMenuView_android_paddingBottom, paddingBottom);
            gravity = typedArray.getInteger(R.styleable.GYMenuView_android_gravity, gravity);

            setContentDrawable(typedArray.getDrawable(R.styleable.GYMenuView_contentDrawable));
            setContentDrawableWidthPx(typedArray.getDimensionPixelSize(R.styleable.GYMenuView_contentDrawableWidth, GYDisplayUtils.dp2px(getContext(), 30)));
            setContentDrawableHeightPx(typedArray.getDimensionPixelSize(R.styleable.GYMenuView_contentDrawableHeight, GYDisplayUtils.dp2px(getContext(), 30)));
            setContentDrawableRadiusPx(typedArray.getDimensionPixelSize(R.styleable.GYMenuView_contentDrawableRadius, 0));
            typedArray.recycle();
//            textCursorWidth = typedArray.getDimensionPixelSize(R.styleable.GYMenuView_textCursorWidth, textCursorWidth);
        }
//        if (textCursorDrawable == null) {
//            textCursorDrawable = GYDrawableUtils.shape(textCursorWidth, 1000, textCursorColor);
//        }
        if (textSizePx != WRAP_CONTENT) {
            leftTextSizePx = textSizePx;
            rightTextSizePx = textSizePx;
        }
        if (textColor != WRAP_CONTENT) {
            leftTextColor = textColor;
            rightTextColor = textColor;
        }
        if (textHintColor != WRAP_CONTENT) {
            leftHintColor = textHintColor;
            rightHintColor = textHintColor;
        }
        if (padding != WRAP_CONTENT) {
            paddingLeft = padding;
            paddingTop = padding;
            paddingRight = padding;
            paddingBottom = padding;
        }

        contentLL.setPadding(Math.round(paddingLeft), Math.round(paddingTop), Math.round(paddingRight), Math.round(paddingBottom));
        contentLL.setGravity(gravity);

        setLeftSingleLine(leftSingleLine);
        setRightSingleLine(rightSingleLine);
        setLeftMaxLength(leftMaxLength);
        setRightMaxLength(rightMaxLength);

        leftTV.getViewSet().setBold(leftTextBold);
//        rightContentTv.getViewSet().setBold(rightTextBold);
        rightContentET.getViewSet().setBold(rightTextBold);
        if (inputType != WRAP_CONTENT) {
//            rightContentTv.setInputType(inputType);
            rightContentET.setInputType(inputType);
        }

        setLeftDrawable(leftDrawable);
        setLeftDrawableSizePx(leftDrawableWidthPx, leftDrawableHeightPx);
        setRightDrawable(rightDrawable);
        setRightDrawableSizePx(rightDrawableWidthPx, rightDrawableHeightPx);

        initLeftText();
        initLeftSpacing();
        initRightText();
        initRightSpacing();
        initSpacing();
        initState();
        setLineHeightPx(lineHeight);
        setLineShow(lineShow);
        setLineColor(lineColor);
        initContentLL();
        setLineMarginPx(lineMarginLeftPx, lineMarginRightPx);
        setTextWidthProportion(0, 1);
        if (!TextUtils.isEmpty(textWidthProportion) && textWidthProportion.contains(":")) {
            String[] strings = textWidthProportion.split(":");
            if (strings.length == 2 && GYUtils.isNumber(strings[0]) && GYUtils.isNumber(strings[1])) {
                setTextWidthProportion(Integer.parseInt(strings[0]), Integer.parseInt(strings[1]));
            }
        }
    }

    private void initContentLL() {
        contentLL.setPadding(marginLeftPx, 0, marginRightPx, 0);
    }

    private void initLeftText() {
        leftTV.getViewSet().setHint(leftHint)
                .setHintTextColor(leftHintColor)
                .setText(leftText)
                .setTextColor(leftTextColor)
                .setTextSizePx(leftTextSizePx == WRAP_CONTENT ? normalTextSize : leftTextSizePx);
    }

    private void initLeftSpacing() {
        LayoutParams layoutParams = (LayoutParams) leftImageView.getLayoutParams();
        layoutParams.rightMargin = leftSpacingPx;
        leftImageView.setLayoutParams(layoutParams);
    }

    private void initRightText() {
        rightContentET.getViewSet().setText(rightText)
                .setHint(rightHint)
                .setHintTextColor(rightHintColor)
                .setTextColor(rightTextColor)
                .setTextSizePx(rightTextSizePx == WRAP_CONTENT ? normalTextSize : rightTextSizePx)
                .setMinWidthPx(rightTextSizePx == WRAP_CONTENT ? normalTextSize : rightTextSizePx);
//        rightContentTv.getViewSet().setText(rightText)
//                .setHint(rightHint)
//                .setHintTextColor(rightHintColor)
//                .setTextColor(rightTextColor)
//                .setTextSizePx(rightTextSizePx == WRAP_CONTENT ? normalTextSize : rightTextSizePx);
//        if (textCursorDrawable == 0) {
//            GYUtils.setCursorDrawableColor(rightET, textCursorColor);
//        } else {
//            rightET.setTextCursorDrawable(textCursorDrawable);
//        }
    }

    private void initRightSpacing() {
        if (rightImageView.getVisibility() == VISIBLE) {
            LayoutParams layoutParams = (LayoutParams) rightImageView.getLayoutParams();
            layoutParams.leftMargin = rightSpacingPx;
            rightImageView.setLayoutParams(layoutParams);
        }
    }

    private void initSpacing() {
        LayoutParams layoutParams = (LayoutParams) rightLL.getLayoutParams();
        layoutParams.setMargins(spacingPx, 0, 0, 0);
        rightLL.setLayoutParams(layoutParams);
    }

    private void initState() {
        for (View view : rightLL.getViewSet().getViews()) {
            view.setVisibility(GONE);
        }
        switch (style) {
            case Style.NORMAL://显示-不可编辑
                rightContentET.setVisibility(View.VISIBLE);
                rightContentET.getViewSet().setEdit(false);
                break;
            case Style.EDIT://显示-可编辑
                rightContentET.setVisibility(View.VISIBLE);
                rightContentET.getViewSet().setEdit(true);
                break;
            case Style.IMAGE://图片
                contentIv.setVisibility(View.VISIBLE);
                break;
            case Style.SWITCH://开关
                contentSwitch.setVisibility(VISIBLE);
                break;
        }
    }

    public GYSwitch getContentSwitch() {
        return contentSwitch;
    }

    public GYMenuView setTextWidthProportion(int left, int right) {
        if (left == 0) {
            leftTV.getViewSet().setSizePx(WRAP_CONTENT, WRAP_CONTENT, 0);
        } else {
            leftTV.getViewSet().setSizePx(0, WRAP_CONTENT, left);
        }
        if (right == 0) {
            rightLL.getViewSet().setSizePx(WRAP_CONTENT, WRAP_CONTENT, 0);
        } else {
            rightLL.getViewSet().setSizePx(0, WRAP_CONTENT, right);
        }
        return this;
    }

    public GYMenuView setLineMarginPx(int lineMarginLeftPx, int lineMarginRightPx) {
        this.lineMarginLeftPx = lineMarginLeftPx;
        this.lineMarginRightPx = lineMarginRightPx;
        topLineView.getViewSet().setMarginPx(lineMarginLeftPx, 0, lineMarginRightPx, 0);
        bottomLineView.getViewSet().setMarginPx(lineMarginLeftPx, 0, lineMarginRightPx, 0);
        return this;
    }

    public GYMenuView setLineMarginDp(int lineMarginLeftDp, int lineMarginRightDp) {
        return setLineMarginPx(GYDisplayUtils.dp2px(getContext(), lineMarginLeftDp), GYDisplayUtils.dp2px(getContext(), lineMarginRightDp));
    }

    public GYMenuView setLineMarginLeftPx(int lineMarginLeftPx) {
        return setLineMarginPx(lineMarginLeftPx, lineMarginRightPx);
    }

    public GYMenuView setLineMarginLeftDp(int lineMarginLeftDp) {
        return setLineMarginLeftPx(GYDisplayUtils.dp2px(getContext(), lineMarginLeftDp));
    }

    public GYMenuView setLineMarginRightPx(int lineMarginRightPx) {
        return setLineMarginPx(lineMarginLeftPx, lineMarginRightPx);
    }

    public GYMenuView setLineMarginRightDp(int lineMarginRightDp) {
        return setLineMarginRightPx(GYDisplayUtils.dp2px(getContext(), lineMarginRightDp));
    }

    public GYMenuView setContentDrawable(Drawable contentDrawable) {
        contentIv.setImageDrawable(contentDrawable);
        return this;
    }

    public GYMenuView setContentDrawableWidthPx(int contentDrawableWidthPx) {
        contentIv.getViewSet().setWidthPx(contentDrawableWidthPx);
        return this;
    }

    public GYMenuView setContentDrawableHeightPx(int contentDrawableHeightPx) {
        contentIv.getViewSet().setHeightPx(contentDrawableHeightPx);
        return this;
    }

    public GYMenuView setContentDrawableRadiusPx(int contentDrawableRadiusPx) {
        contentIv.getImageBuilder().setImageRadiusPx(contentDrawableRadiusPx).build();
        return this;
    }

    public GYImageView getContentIv() {
        return contentIv;
    }

    public GYMenuView addContentViews(View... views) {
        return addContentViews(Arrays.asList(views));
    }

    public GYMenuView addContentViews(int index, View... views) {
        return addContentViews(index, Arrays.asList(views));
    }

    public GYMenuView addContentViews(List<View> viewList) {
        return addContentViews(-1, viewList);
    }

    public GYMenuView addContentViews(int index, List<View> viewList) {
        contentLL.getViewSet().addViews(index, viewList);
        return this;
    }

    public GYMenuView removeContentAllViews() {
        contentLL.removeAllViews();
        return this;
    }

    public GYMenuView setInputType(int inputType) {
        this.inputType = inputType;
        rightContentET.setInputType(inputType);
        return this;
    }

    public int getInputType() {
        return inputType;
    }

    private OnStyleChangeListener onStyleChangeListener;

    public interface OnStyleChangeListener {
        void onStateChange(GYMenuView gyMenuView, int beforeStyle, int afterStyle);
    }

    public GYMenuView setOnStyleChangeListener(OnStyleChangeListener onStyleChangeListener) {
        this.onStyleChangeListener = onStyleChangeListener;
        return this;
    }

    public int getMarginLeftPx() {
        return marginLeftPx;
    }

    public int getMarginRightPx() {
        return marginRightPx;
    }
}
